﻿/*
///    This file is part of BannerLib4Net.
///
///    BannerLib4Net is free software: you can redistribute it and/or modify
///    it under the terms of the GNU General Public License as published by
///    the Free Software Foundation, either version 3 of the License, or
///    (at your option) any later version.

///    BannerLib4Net is distributed in the hope that it will be useful,
///    but WITHOUT ANY WARRANTY; without even the implied warranty of
///    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
///    GNU General Public License for more details.
///
///    You should have received a copy of the GNU General Public License
///    along with BannerLib4Net.  If not, see <http://www.gnu.org/licenses/>.
*/


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using log4net;
using log4net.Config;

namespace BannerLib4Net.Core.Logging.Log4Net
{
    public class Log4NetLogger : BannerLib4Net.Core.Logging.ILogger
    {
        private static ILog log = null;

        public Log4NetLogger(String name)
        {
            Initialize(name);
        }

        private void Initialize(String name)
        {
            Log4NetLogger.log = LogManager.GetLogger(name);

            String basePath = Path.GetDirectoryName(Assembly.GetAssembly(this.GetType()).Location);
            String filePath = basePath + Path.DirectorySeparatorChar + "log4net.config";

            FileInfo logConfig = new FileInfo(filePath);

            if (logConfig.Exists)
            {
                XmlConfigurator.ConfigureAndWatch(logConfig);
            }
            else
            {
                throw new Exception(String.Format("Could not find the log4net.config file to configure log4net, Using Path: {0}", filePath));
            }
        }



        public void LogDebug(string message)
        {
            Log4NetLogger.log.Debug(message);

        }

        public void LogDebug(string message, Exception ex)
        {
            Log4NetLogger.log.Debug(message, ex);
        }

        public void LogError(string message)
        {
            Log4NetLogger.log.Error(message);
        }

        public void LogError(string message, Exception ex)
        {
            Log4NetLogger.log.Error(message, ex);
        }

        public void LogFatal(string message)
        {
            Log4NetLogger.log.Fatal(message);
        }

        public void LogFatal(string message, Exception ex)
        {
            Log4NetLogger.log.Fatal(message, ex);
        }

        public void LogInfo(string message)
        {
            Log4NetLogger.log.Info(message);
        }

        public void LogInfo(string message, Exception ex)
        {
            Log4NetLogger.log.Info(message, ex);
        }

        public void LogWarn(string message)
        {
            Log4NetLogger.log.Warn(message);
        }

        public void LogWarn(string message, Exception ex)
        {
            Log4NetLogger.log.Warn(message, ex);
        }

    }
}
